package com.yy.student.controller;

import com.yy.student.entity.StudentEntity;
import com.yy.student.service.StudentSer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class StudentController {
    @Autowired
    private StudentSer ser;
    @PreAuthorize("hasAuthority('yy:student:view')")
    @GetMapping("students")
    public List<StudentEntity> findAll(){
        return ser.findAll();
    }
    @PreAuthorize("hasAuthority('yy:student:view')")
    @GetMapping("students/{id}")
    StudentEntity findById(@PathVariable("id") Long id){
        return ser.findById(id);
    }
    @PreAuthorize("hasAuthority('yy:student:add')")
    @PostMapping("students")
    StudentEntity save(StudentEntity student){
        return ser.save(student);
    }
    @PreAuthorize("hasAuthority('yy:student:del')")
    @DeleteMapping("students")
    void delete(StudentEntity student){
        ser.delete(student);
    }
}
